﻿$(document).ready(function () {
    function checkBox(obj, objName) {
        var checks = $(obj).attr('checked');
        if (checks) {
            $('input[name=' + objName + ']').attr('checked', 'checked');

        }
        else {
            $('input[name=' + objName + ']').attr('checked', false);
        }
    }


});
/**********************category page******************/
$('.check-all').click(function () {
    checkBox(this, 'tee_checkbox');
});
$('#setCate').click(function () {
    var cid = $('#sl_setCategory').val();
    var ids = "";
    $('input[name=item_check]').each(function () {
        if ($(this).get(0).checked) {
            ids += $(this).val() + ",";
        }
    });
    if (ids != "") {
        var idList = ids.substr(0, ids.length - 1);
        $.ajax({
            type: 'get',
            dataType: 'text',
            url: 'Ajax/AjaxHandler.ashx',
            data: 'm=setcategory&ids=' + encodeURIComponent(idList) + '&cid=' + cid + '&i=' + Math.random() + '',
            success: function (data) {
                if (null != data && data.length != 0 && data == 'y') {
                    alert('设置作品分类成功!');
                    return false;
                }
            }
        });
    }
});
//获取select值并付给控件
$('#sl_source').val(getCookie('sl_source') == null ? 0 : getCookie('sl_source'))
$('#sl_status').val(getCookie('sl_status') == null ? 0 : getCookie('sl_status'))
$('#sl_category').val(getCookie('sl_category') == null ? 0 : getCookie('sl_category'))

//设置select值到cookie
$('#sl_source').change(function () {
    setCookie('sl_source', $('#sl_source').val());
});
$('#sl_status').change(function () {
    setCookie('sl_status', $('#sl_status').val());
});
$('#sl_category').change(function () {
    setCookie('sl_category', $('#sl_category').val());
});

function setCookie(name, value) {
    var Days = 1;
    var exp = new Date();    //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + Days * 24 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}
function getCookie(name) {
    var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
    if (arr != null) return unescape(arr[2]); return null;
}
function delCookie(name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = getCookie(name);
    if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}